import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;

import pulpcore.Input;
import pulpcore.Stage;
import pulpcore.image.BlendMode;
import pulpcore.image.Colors;
import pulpcore.image.CoreFont;
import pulpcore.sprite.Button;
import pulpcore.sprite.Group;
import pulpcore.sprite.Label;
import pulpcore.sprite.Slider;
import pulpcore.sprite.Sprite;
import pulpfizz.pulp.body.Java2DSprite;

public class Menus
{

	public static class MainMenu extends Group
	{

		public Slider slider;
		public Button play;

		public MainMenu()
		{
			super();

			final int w = 200;
			final int h = 200;
			Java2DSprite j2d = new Java2DSprite(0, 0, w + 4, h + 4)
			{

				@Override
				protected void draw(Graphics2D g)
				{
					g.setColor(Color.WHITE);
					g.fillRoundRect(2, 2, w, h, 30, 30);

					g.setStroke(new BasicStroke(2));
					g.setColor(Color.GRAY);
					g.drawRoundRect(2, 2, w, h, 30, 30);
				}

				@Override
				protected boolean needsRedraw()
				{
					return false;
				}

			};
			j2d.setBlendMode(BlendMode.Add());
			j2d.alpha.set(150);
			j2d.setAnchor(Sprite.CENTER);
			add(j2d);

			int y = -70;

			Label l = new Label(CoreFont.getSystemFont().tint(Colors.WHITE).scale(1.5), "Two player", 0, y);
			l.setAnchor(Sprite.CENTER);
			add(l);

			y = 0;

			slider = new Slider("slider.png", "slider-thumb.png", 0, y);
			slider.setAnchor(Sprite.CENTER);
			slider.setCursor(Input.CURSOR_HAND);
			slider.setRange(1, 7);
			slider.value.set(3);
			add(slider);

			l = new Label(CoreFont.getSystemFont().tint(Colors.WHITE), "Goals per game: %d", 0, y - 20);
			l.setAnchor(Sprite.CENTER);
			l.setFormatArg(slider.value);
			add(l);

			y = 65;

			play = Button.createLabeledButton("Play!", 0, y);
			play.setSize(120, 50);
			play.setAnchor(Sprite.CENTER);
			add(play);

			setAnchor(Sprite.CENTER);
		}
	}

	public static class GameOverMenu extends Group
	{
		Button again;
		Button mainMenu;

		public GameOverMenu(Player winner)
		{
			super();
			x.set(Stage.getWidth()/2);
			y.set(Stage.getHeight()/2);
			final int w = 200;
			final int h = 200;
			Java2DSprite j2d = new Java2DSprite(0, 0, w + 4, h + 4)
			{

				@Override
				protected void draw(Graphics2D g)
				{
					g.setColor(Color.WHITE);
					g.fillRoundRect(2, 2, w, h, 30, 30);

					g.setStroke(new BasicStroke(2));
					g.setColor(Color.GRAY);
					g.drawRoundRect(2, 2, w, h, 30, 30);
				}

				@Override
				protected boolean needsRedraw()
				{
					return false;
				}

			};
			j2d.setBlendMode(BlendMode.Add());
			j2d.alpha.set(150);
			j2d.setAnchor(Sprite.CENTER);
			add(j2d);

			int y = -70;

			Label l = new Label(CoreFont.getSystemFont().tint(winner.color.getRGB()).scale(1.5), "Winner!", 0, y);
			l.setAnchor(Sprite.CENTER);
			add(l);

			y = 0;

			again = Button.createLabeledButton("Play again", 0, y);
//			again.setSize(120, 50);
			again.setAnchor(Sprite.CENTER);
			add(again);

			y = 60;

			mainMenu = Button.createLabeledButton("Main Menu", 0, y);
//			mainMenu.setSize(120, 50);
			mainMenu.setAnchor(Sprite.CENTER);
			add(mainMenu);
		}

		@Override
		public void update(int elapsedTime)
		{
			super.update(elapsedTime);

			if (again.isClicked())
			{
				TwoPlayerScene curScene = (TwoPlayerScene) Stage.getScene();
				TwoPlayerScene scene = new TwoPlayerScene();
				scene.setWinningScore(curScene.getWinningScore());
				scene.sf = curScene.sf;
				Stage.replaceScene(scene);
			}
			if (mainMenu.isClicked())
			{
				Stage.replaceScene(new MainScene());
			}
		}
	}
}
